/**
 * 1.  类丶属性丶方法 丶参数装饰器组合案例实现 
 */


// 1.  类丶属性丶方法 丶参数装饰器组合案例实现   
// 2.  执行顺序 属性>方法参数>方法>类        注：如果有多个同样的装饰器，它会先执行后面的装饰器。


function UrlPropDecorator(targetClassPrototype: any, attrname: any) {

  console.log("=============1执行属性装饰器==============")
  console.log("targetClassPrototype:", targetClassPrototype);
  console.log("属性名:", attrname);
}

function paramDecorator(targetClassPrototype: any, paramname: string, paramindex: number) {
  console.log("=============2+4执行参数装饰器==============")
  console.log("targetClassPrototype:", targetClassPrototype);
  console.log("参数名:", paramname);
  console.log("参数索引:", paramindex);
}

function firstMethodDecorator(targetClassPrototype: any,
  methodname: string) {
  console.log("=============3执行第一个方法装饰器==============")
  console.log("类名:", targetClassPrototype)//  类原型对象变量   URLInfo { show: [Function] }
  console.log("方法名:", methodname);//key
}


function secondMethodDecorator(params: string) {
  return function (targetClassPrototype: any, methodname: string) {
    console.log("=============5执行第二个方法装饰器==============")
    console.log("类名:", targetClassPrototype)//  类原型对象变量   URLInfo { show: [Function] }
    console.log("方法名:", methodname);//key
  }
}

function constructorDecorator(params: any) {
  return function (targetClassPrototype: any, paramname: string, paramindex: number) {
    console.log("==========6构造器参数装饰器============")
    console.log("构造器参数装饰器", targetClassPrototype);
    console.log("构造器参数名为:", paramname);
    console.log("构造器参数索引位置:", paramindex);
  }
}

function URLInfoDecorator(targetClassPrototype: any) {
  console.log("==========7类装饰器============")
  console.log("targetClassPrototype:", targetClassPrototype);
}



@URLInfoDecorator
class URLInfo {
  constructor(@constructorDecorator("url") public uri: string) {

  }

  @UrlPropDecorator
  public url: string = "https://www.imooc.com"


  @firstMethodDecorator
  methodOne(@paramDecorator data: string) {
    console.log("this:", this);
    console.log("目标类:", this.uri)
  }

  @secondMethodDecorator("yes")
  methodTwo(@paramDecorator address: string) {
    console.log(address)
  }
}
export { }